﻿<Window x:Class="FloydPink.Flickr.Downloadr.UI.PreferencesWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Preferences - flickr downloadr"
        ResizeMode="NoResize"
        WindowStartupLocation="CenterOwner" mc:Ignorable="d"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignWidth="520"
        SizeToContent="WidthAndHeight"
        xmlns:controls="clr-namespace:FloydPink.Flickr.Downloadr.UI.Controls"
        xmlns:enums="clr-namespace:FloydPink.Flickr.Downloadr.Model.Enums;assembly=FloydPink.Flickr.Downloadr.Model"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:behaviors="clr-namespace:FloydPink.Flickr.Downloadr.UI.Behaviors"
        xmlns:converters="clr-namespace:FloydPink.Flickr.Downloadr.UI.Converters"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Icon="/flickr%20downloadr;component/Images/icon.png">
    <Window.Resources>
        <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="DownloadSizes">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="enums:PhotoDownloadSize" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider MethodName="GetItems" ObjectType="{x:Type enums:PhotoMetadata}" x:Key="Metadatas" />
        <ObjectDataProvider MethodName="GetItems" ObjectType="{x:Type enums:SafeSearch}" x:Key="SafetyLevels" />
        <converters:BoolInverterConverter x:Key="BoolInverterConverter" />
    </Window.Resources>

    <Grid Height="480" Width="510">
        <Grid
            DataContext="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=Preferences, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="50" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="40" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <StackPanel Grid.Row="0" Margin="15,0,0,0">
                    <Label Content="Preferences" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="24" />
                </StackPanel>
                <StackPanel Grid.Row="1" Orientation="Vertical" Grid.IsSharedSizeScope="True" Margin="10 0">
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Filename:</Label>
                        <RadioButton GroupName="Filename" Content="Photo ID" Grid.Column="1" Margin="3, 6, 0, 0"
                                     IsChecked="{Binding Path=TitleAsFilename, Converter={StaticResource BoolInverterConverter}}" />
                        <RadioButton GroupName="Filename" Content="Photo Title" Grid.Column="2" Margin="3, 6, 0, 0"
                                     IsChecked="{Binding Path=TitleAsFilename}" />
                    </Grid>
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="30" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Download Location:</Label>
                        <TextBox Name="DownloadLocationTextbox" Grid.Column="1" IsReadOnly="True"
                                 IsReadOnlyCaretVisible="True" Text="{Binding Path=DownloadLocation}" />
                        <Button Grid.Column="2" Content="..." Width="25" Height="25"
                                Click="SelectDownloadFolderButtonClick" />
                    </Grid>
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Download Size:</Label>
                        <ComboBox Grid.Column="1" ItemsSource="{Binding Source={StaticResource DownloadSizes}}"
                                  SelectedItem="{Binding Path=DownloadSize}" />
                    </Grid>
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Photos Per Page:</Label>
                        <ComboBox Grid.Column="1" SelectedValue="{Binding Path=PhotosPerPage}"
                                  SelectedValuePath="Content">
                            <ComboBoxItem>
                                <sys:Int32>25</sys:Int32>
                            </ComboBoxItem>
                            <ComboBoxItem>
                                <sys:Int32>50</sys:Int32>
                            </ComboBoxItem>
                            <ComboBoxItem>
                                <sys:Int32>75</sys:Int32>
                            </ComboBoxItem>
                            <ComboBoxItem>
                                <sys:Int32>100</sys:Int32>
                            </ComboBoxItem>
                        </ComboBox>
                    </Grid>
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Metadata:</Label>
                        <ListBox Grid.Column="1" SelectionMode="Multiple"
                                 ItemsSource="{Binding Source={StaticResource Metadatas}}"
                                 behaviors:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding Metadata}">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="{x:Type ListBoxItem}">
                                    <Setter Property="IsSelected" Value="{Binding Metadata}" />
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <WrapPanel>
                                        <CheckBox IsEnabled="False" Name="SelectedCheck" Focusable="False"
                                                  VerticalAlignment="Center" />
                                        <ContentPresenter Content="{Binding Mode=OneTime}" Margin="2,0" />
                                    </WrapPanel>
                                    <DataTemplate.Triggers>
                                        <DataTrigger
                                            Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"
                                            Value="True">
                                            <Setter TargetName="SelectedCheck" Property="IsChecked" Value="True" />
                                        </DataTrigger>
                                    </DataTemplate.Triggers>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Safety Level:</Label>
                        <ComboBox Grid.Column="1" ItemsSource="{Binding Source={StaticResource SafetyLevels}}"
                                  SelectedItem="{Binding Path=SafetyLevel}" />
                    </Grid>
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Tags:</Label>
                        <RadioButton GroupName="Tags" Content="Internal" Grid.Column="1" Margin="3, 6, 0, 0"
                                     IsChecked="{Binding Path=NeedOriginalTags, Converter={StaticResource BoolInverterConverter}}" />
                        <RadioButton GroupName="Tags" Content="Original (Slower download)" Grid.Column="2"
                                     Margin="3, 6, 0, 0"
                                     IsChecked="{Binding Path=NeedOriginalTags}" />
                    </Grid>
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="30" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Cache Location:</Label>
                        <TextBox Name="CacheLocationTextbox" Grid.Column="1" IsReadOnly="True"
                                 IsReadOnlyCaretVisible="True" Text="{Binding Path=CacheLocation}" />
                        <Button Grid.Column="2" Content="..." Width="25" Height="25"
                                Click="SelectCacheFolderButtonClick" />
                    </Grid>
                    <Grid Margin="7">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Label" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0">Cache Size:</Label>
                        <Label Grid.Column="1" x:Name="CacheSize" Margin="0,0,2,0" />
                        <Button Grid.Column="2" Content="Empty Cache" x:Name="EmptyCacheButton" Width="80" Height="22"
                                ToolTip="Empty the cache folder" HorizontalAlignment="Left" Click="EmptyCacheClick" />
                    </Grid>
                </StackPanel>
            </Grid>
            <Grid Grid.Row="1" VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Column="0" HorizontalAlignment="Left">
                    <Button Content="Cancel" ToolTip="Cancel and go back to Login screen" Width="80" Height="28"
                            Margin="5,0" Click="CancelButtonClick" />
                </StackPanel>
                <StackPanel Grid.Column="1" HorizontalAlignment="Center">
                    <Button Content="Defaults" ToolTip="Change to default values" Width="80" Height="28"
                            Click="DefaultsButtonClick" />
                </StackPanel>
                <StackPanel Grid.Column="2" HorizontalAlignment="Right">
                    <Button Content="Save" ToolTip="Save and go to Photo Browser screen" Width="80" Height="28"
                            Margin="5,0" Click="SaveButtonClick" />
                </StackPanel>
            </Grid>
        </Grid>
        <AdornerDecorator Name="Spinner" Visibility="Collapsed">
            <controls:Spinner Cancellable="True" />
        </AdornerDecorator>
    </Grid>
</Window>